home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 34 / Mac Magazin and MacEasy Magazine CD - Issue 34.iso / Grafik & Text / Alpha ƒ / Tcl / Modes / latexLoad.tcl < prev    next >
Text File  |  1996-08-15  |  8KB  |  259 lines

  1. #############################################################################
  2. # Install the files that support one of the LaTeX modes.
  3. # The global flag $latexVersion indicates which mode (LaTeX 2.09 or LaTeX2e)
  4. # is currently installed.
  5. #
  6. # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
  7. # (updated 4/29/95 for latex.tcl v2.4)
  8. # (updated 7/02/96 for latex.tcl v3.2 TRS)
  9. #
  10. proc loadLaTeX {} {
  11.     global HOME latexVersion
  12.     
  13.     set oldWd [pwd]
  14.     cd $HOME
  15.     
  16.     set latex209Dir ":LaTeX:latex 2.09"
  17.     set latex209Files {
  18.             {"latexMode.tcl" ":Tcl:Modes" 1}
  19.             {"latex.tcl" ":Tcl:Modes" 1}
  20.             {"smart.tcl" ":Tcl:Modes" 0}
  21.             {"LaTeX Help" ":Help" 0}
  22.             {"LaTeX Key Bindings" ":Help" 0}
  23.     }
  24.  
  25.     set latex2eDir ":LaTeX:latex 2e"
  26.     set latex2eFiles {
  27.             {"latexMode.tcl" ":Tcl:Modes" 1}
  28.             {"latex.tcl" ":Tcl:Modes" 1}
  29.             {"latexComm.tcl" ":Tcl:Modes" 0}
  30.             {"latexEngine.tcl" ":Tcl:Modes" 0}
  31.             {"latexFilesets.tcl" ":Tcl:Modes" 0}
  32.             {"latexKeys.tcl" ":Tcl:Modes" 0}
  33.             {"latexMacros.tcl" ":Tcl:Modes" 0}
  34.             {"latexMenu.tcl" ":Tcl:Modes" 0}
  35.             {"latexPatches.tcl" ":Tcl:Modes" 0}
  36.             {"latexSmart.tcl" ":Tcl:Modes" 0}
  37.             {"LaTeX Help" ":Help" 0}
  38.     }
  39.     set report 0
  40.  
  41.     if {$latexVersion == "2e"} {
  42.         if {[askyesno "Install LaTeX 2.09?"] == "yes"} {
  43.             set report [installFiles $latex209Dir $latex209Files $latex2eDir $latex2eFiles 0 1 TeX]
  44.             if {$report != 0} {
  45. # uncomment these lines if new files are not automatically sourced
  46. #                 alertnote "Now quit and restart Alpha to load LaTeX 2.09 mode"
  47. #                 set latexVersion "2.09"
  48. # and comment out this one
  49.                 alertnote "LaTeX 2.09 support was successfully installed"
  50. #
  51.             } else {
  52.                 alertnote "The installation was cancelled"
  53.             }
  54.         }
  55.     } elseif {$latexVersion == "2.09"} {
  56.         if {[askyesno "Install LaTeX 2e?"] == "yes"} {
  57.             set report [installFiles $latex2eDir $latex2eFiles $latex209Dir $latex209Files 0 1 TeX]
  58.             if {$report != 0} {
  59. # uncomment these lines if new files are not automatically sourced
  60. #                alertnote "Now quit and restart Alpha to load LaTeX2e mode"
  61. #                set latexVersion "2e"
  62. # and comment out this one
  63.                 alertnote "LaTeX2e support was successfully installed"
  64. #
  65.             } else {
  66.                 alertnote "The installation was cancelled"    
  67.             }
  68.         }
  69.     }
  70.     
  71.     if {$report != 0} {
  72.         set timePat {([0-9/]+) ([^:]+):([^:]+):([^:]+) (..)}
  73.         regsub $timePat [join [mtime [now] short]] {\1 \2.\3\5} timestamp
  74.         set fname "$HOME:LaTeX:Install Report $timestamp"
  75.         
  76.         set tmpfid [open $fname "w+"]
  77.         puts $tmpfid $report
  78.         close $tmpfid
  79.     }
  80.     
  81.     cd $oldWd
  82. }
  83.  
  84. ##############################################################################
  85. # Install a list of files from $InstallDir into various destination folders.
  86. #
  87. # Each item of $installList contains a list of two items : a file and its 
  88. # destination directory.  If $backupDir and $backupList are given, then the 
  89. # files from this list are first removed from the indicated directories and 
  90. # saved in $backupDir.  If $deleteOld is 1, then an old file is just
  91. # deleted if the backup directory doesn't exist or if it already contains
  92. # the file; if $overwriteBackups is 1, then old backup files will be
  93. # overwritten ($deleteOld is checked before $overwriteBackups).
  94. #
  95. # If any Tcl source files (.tcl) are installed, then they are also automatically
  96. # sourced and "rebuildTclIndices" is called to update the autoloader index files.
  97. # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
  98. #
  99. #             if {[file extension $file] == ".tcl"} {
  100.  
  101. proc installFiles {installDir installList backupDir backupList 
  102.                    {deleteOld 0} {overwriteBackups 0} {deleteBindings 0}} {
  103.     global HOME latexMenu
  104.     set script {}
  105.     set report ""
  106.     set askedAlready 0
  107.     set removed {}
  108.     
  109.     set script2 {}
  110.     set report2 ""
  111.     
  112.     lappend script [list uplevel {#0} [list catch [list removeMenu $latexMenu]]]
  113.  
  114.     if {! [file exists $backupDir] && ! $deleteOld} {
  115.         lappend script [list mkdir $backupDir]
  116.         append report "Created backup directory \"$backupDir\"\n"
  117.     } 
  118.     
  119.     foreach item $backupList {
  120.         set file [lindex $item 0]
  121.         set dir [lindex $item 1]
  122.         
  123.         set frompath ${dir}:${file}
  124.         set topath ${backupDir}:${file}
  125.  
  126.         if {[closeInstallFile $file] == "cancel"} {
  127.             return 0
  128.         }        
  129.         
  130.         if {[file exists $frompath]} {
  131.             if {[file exists $topath]} {
  132.                 if {!$deleteOld && !$overwriteBackups && !$askedAlready} {
  133.                     if {[askyesno "Can I delete old files that are already backed up?"] == "yes"} {
  134.                         set deleteOld 1
  135.                     } elseif {[askyesno "Can I overwrite previous backup files?"] == "yes"} {
  136.                         set overwriteBackups 1
  137.                     }
  138.                     set askedAlready 1
  139.                 }
  140.                 if {$deleteOld} {
  141.                     lappend script [list removeFile $frompath]
  142.                     append report "Deleted old file \"$file\" from folder \"$dir\"\n"
  143.                     lappend removed $frompath
  144.  
  145.                 } elseif {$overwriteBackups} {
  146.                     lappend script [list removeFile $topath]
  147.                     lappend script [list copyFile $frompath $topath]
  148.                     lappend script [list removeFile $frompath]
  149.                     append report "Saved old file \"$file\" in folder \"$backupDir\"\n"
  150.                     lappend removed $frompath
  151.                 
  152.                 } else {
  153.                     message "No files were moved or deleted"
  154.                     return 0
  155.                 }
  156.             } else {
  157.                 lappend script [list copyFile $frompath $topath]
  158.                 lappend script [list removeFile $frompath]
  159.                 append report "Saved old file \"$file\" in folder \"$backupDir\"\n"
  160.                 lappend removed $frompath
  161.             }
  162.         } else {
  163.             append report "-- old file \"$file\" was missing from folder \"$dir\" --\n"
  164.         }
  165.     }
  166.     
  167.     append report "\n"
  168.     
  169.     foreach item $installList {
  170.         set file [lindex $item 0]
  171.         set dir [lindex $item 1]
  172.         set loadable [lindex $item 2]
  173.         set frompath ${installDir}:${file}
  174.         set topath ${dir}:${file}
  175.         
  176.         if {[closeInstallFile $file] == "cancel"} {
  177.             return 0
  178.         }        
  179.  
  180.         if {[file exists $frompath]} {
  181.             if {[file exists $topath] && [lsearch -exact $removed $topath] < 0} {
  182.                 if {[askyesno "Can I overwrite the old copy of $file?"] == "yes"} {
  183.                     lappend script [list removeFile $topath]
  184.                     append report "Deleted old file \"$file\" in folder \"$dir\"\n"
  185.                     lappend removed $topath
  186.                 } else {
  187.                     return 0
  188.                 }
  189.             }
  190.             lappend script [list copyFile $frompath $topath]
  191.             append report "Copied file \"$file\" from folder \"$installDir\" to \"$dir\"\n"
  192.             
  193.             if { $loadable } {
  194.                 lappend script2 [list uplevel {#0} [list source ${HOME}$topath]]
  195.                 append report2 "Loaded the new file \"$file\"\n"
  196.             }
  197.         } else {
  198.             message "Installation aborted - no files were moved or deleted"
  199.             alertnote "Install file \"$file\" is missing"
  200.             return 0
  201.         }
  202.     }
  203.  
  204.     if {[llength $script2]} {
  205. # comment out these lines to stop automatic sourcing of newly loaded .tcl files
  206. # (_Don't_ change the lines creating $script2, above)
  207. #         if {$deleteBindings != 0} {
  208. #             lappend script [list deleteModeBindings $deleteBindings]
  209. #             append report "\nRemoved the old ${deleteBindings}-mode key bindings\n"
  210. #         }
  211.         set script [concat $script $script2]
  212.         append report "\n"
  213.         append report $report2
  214.  
  215.         lappend script [list message "Rebuilding Filesets menu…"]
  216.         lappend script rebuildAllFilesets
  217.         append report "\nRebuilt Filesets menu"
  218.  
  219.         lappend script [list message "Rebuilding Tcl indices…"]
  220.         lappend script rebuildTclIndices
  221.         append report "\nRebuilt Tcl indices\n"
  222.     }
  223.     
  224. # # Uncomment these lines to get a play-by-play of the installation procedure 
  225. # #
  226. #     new -n "* Install Script *"
  227.     foreach item $script {
  228. #     insertText "$item\n"
  229.         eval $item
  230.     }
  231. #     catch {shrinkWindow 1}
  232. #     setWinInfo dirty 0
  233.     
  234.     new -n "* Installation Report *"
  235.     insertText $report "\rYou must now REBOOT ALPHA.\r"
  236.     catch {shrinkWindow 1}
  237.     setWinInfo dirty 0
  238.     setWinInfo read-only 1
  239.  
  240.     return $report
  241. }
  242.  
  243. proc closeInstallFile {file} {
  244.     if {[lsearch -exact [winNames] $file] >= 0} {
  245.         set reply [askyesno -c "Close file $file before installing?"]
  246.         if {$reply == "yes"} {
  247.             bringToFront $file
  248.             killWindow
  249.         } 
  250.         if {$reply == "cancel" || 
  251.             ($reply == "yes" && [lsearch -exact [winNames] $file] >= 0)} {
  252.             message "No files were moved or deleted"
  253.             return "cancel"
  254.         }
  255.     }
  256.     return ""
  257. }
  258.